package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.bean.DaTi;
import com.bw.bean.LaiYuan;
import com.bw.bean.LiuLiangHour;
import com.bw.bean.TestTongJi;
import com.bw.service.MyServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping
@RestController
@ResponseBody
public class MyComtroller {

    @Resource
    MyServiceImpl myService;
    @RequestMapping("/list1")
    public Object list1(){
        List<LiuLiangHour> liuLiangHours = myService.list1();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject o1 = new JSONObject();
        JSONArray a1 = new JSONArray();
        for (LiuLiangHour liuLiangHour : liuLiangHours) {
            a1.add(liuLiangHour.getTime());
        }

        o1.put("categories",a1);
        JSONArray a2 = new JSONArray();
        JSONObject o2 = new JSONObject();
        o2.put("name","新访客数");
        JSONArray a3 = new JSONArray();
        for (LiuLiangHour liuLiangHour : liuLiangHours) {
            a3.add(liuLiangHour.getCount());
        }
        a2.add(o2);
        o2.put("data",a3);
        o1.put("series",a2);
        jsonObject.put("data",o1);
        return jsonObject;
    }

    @RequestMapping("/list2")
    public Object list2(){
        List<DaTi> daTis = myService.list2();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject o1 = new JSONObject();
        JSONArray a1 = new JSONArray();
        JSONObject o2 = new JSONObject();
        o2.put("name","题目内容");
        o2.put("id","subsys");

        JSONObject o3 = new JSONObject();
        o3.put("name","答题次数");
        o3.put("id","module");

        JSONObject o4 = new JSONObject();
        o4.put("name","正确答题");
        o4.put("id","business");

        JSONObject o5 = new JSONObject();
        o5.put("name","正确率");
        o5.put("id","value");

        a1.add(o2);
        a1.add(o3);
        a1.add(o4);
        a1.add(o5);
        o1.put("columns",a1);
        JSONArray a2 = new JSONArray();

        for (DaTi daTi : daTis) {
            JSONObject o6 = new JSONObject();
            o6.put("subsys",daTi.getName());
            o6.put("module",daTi.getCount());
            o6.put("business",daTi.getSum());
            o6.put("value",daTi.getAvg());
            a2.add(o6);
        }

        o1.put("rows",a2);
        jsonObject.put("data",o1);
        return jsonObject;
    }
    @RequestMapping("/list3")
    public Object list3(){
        List<TestTongJi> testTongJis = myService.list3();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject o1 = new JSONObject();
        JSONArray a1 = new JSONArray();
        JSONObject o2 = new JSONObject();
        o2.put("name","试卷名称");
        o2.put("id","subsys");

        JSONObject o3 = new JSONObject();
        o3.put("name","考试人数");
        o3.put("id","module");

        JSONObject o4 = new JSONObject();
        o4.put("name","平均分");
        o4.put("id","business");

        JSONObject o5 = new JSONObject();
        o5.put("name","平均用时");
        o5.put("id","value");

        a1.add(o2);
        a1.add(o3);
        a1.add(o4);
        a1.add(o5);
        o1.put("columns",a1);
        JSONArray a2 = new JSONArray();

        for (TestTongJi testTongJi : testTongJis) {
            JSONObject o6 = new JSONObject();
            o6.put("subsys",testTongJi.getName());
            o6.put("module",testTongJi.getCount());
            o6.put("business",testTongJi.getScore());
            o6.put("value",testTongJi.getTime());
            a2.add(o6);
        }
        o1.put("rows",a2);
        jsonObject.put("data",o1);
        return jsonObject;
    }
    @RequestMapping("/list4")
    public Object list4(){
        List<LaiYuan> laiYuans = myService.list4();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject o1 = new JSONObject();
        JSONArray a1 = new JSONArray();
        for (LaiYuan laiYuan : laiYuans) {
            a1.add(laiYuan.getName());
        }
        o1.put("categories",a1);
        JSONArray a2 = new JSONArray();
        JSONObject o2 = new JSONObject();
        o2.put("name","独立访客数");
        JSONArray a3 = new JSONArray();
        for (LaiYuan laiYuan : laiYuans) {
            a3.add(laiYuan.getCount());
        }
        o2.put("data",a3);
        JSONObject o3 = new JSONObject();
        o3.put("name","会话总数");
        JSONArray a4 = new JSONArray();
        for (LaiYuan laiYuan : laiYuans) {
            a4.add(laiYuan.getSum());
        }
        JSONObject o4 = new JSONObject();
        o4.put("name","浏览页面数");
        JSONArray a5 = new JSONArray();
        for (LaiYuan laiYuan : laiYuans) {
            a5.add(laiYuan.getCou());
        }
        JSONObject o5 = new JSONObject();
        o5.put("name","停留时长");
        JSONArray a6 = new JSONArray();
        for (LaiYuan laiYuan : laiYuans) {
            a6.add(laiYuan.getAvg());
        }
        o1.put("series",a2);
        a2.add(o2);
        jsonObject.put("data",o1);
        return jsonObject;
    }

}
